/* 
 * Copyright 2014 Josef Hertl.
 *
 * Licensed under the Apache License, Version 2.0 (the "License");
 * you may not use this file except in compliance with the License.
 * You may obtain a copy of the License at
 *
 *      http://www.apache.org/licenses/LICENSE-2.0
 *
 * Unless required by applicable law or agreed to in writing, software
 * distributed under the License is distributed on an "AS IS" BASIS,
 * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
 * See the License for the specific language governing permissions and
 * limitations under the License.
 */
package caetus.modelChecking.variable;

import java.util.Collections;
import java.util.LinkedList;
import java.util.List;

/**
 *
 * @author Josef Hertl
 */
public class ModelConstants {

    private static List<ModelBaseVariable> textConstants = new LinkedList<ModelBaseVariable>();

    /**
     * Adds the constant to constant list. The list cannot contain two same
     * constants.
     *
     * @return True if success, false otherwise.
     */
    public static boolean add(ModelBaseVariable e) {
        if (!textConstants.contains(e)) {
            return textConstants.add(e);
        } else {
            return false;
        }
    }

    /**
     * @param text The name of the constant that should be found.
     * @return The required constant.
     */
    public static ModelBaseVariable getConstant(String text) {
        for (ModelBaseVariable modelBaseVariable : textConstants) {
            if (modelBaseVariable.getVariableName().equals(text)) {
                return modelBaseVariable;
            }
        }
        return null;
    }

    /**
     * Used in environment role to list all the constants.
     *
     * @return List of all the constants in the model.
     */
    public static List<ModelBaseVariable> getAllTextConstants() {
        return Collections.unmodifiableList(textConstants);
    }
}
